<?php

namespace App\Http\Requests\service;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait ProblemRequest
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'type_id' => 'required|integer|exists:t_service_problem_type,id',
            'order_sn' => 'required',
            'number' => 'required|integer',
            'weight' => 'required|numeric',
//            'description' => 'required|string',
        ], [
            'type_id.required' => '请选择类型',
            'order_sn.required' => '请填写入仓号',
            'number.required' => '请填写件数',
            'weight.required' => '请填写重量',
//            'description.required' => '请填写描述',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function programme_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'programme' => 'required|integer|in:1,2,3',
        ], [
            'programme.required' => '请选择方案',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function compensate_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'currency_id' => 'required|integer',
            'amount' => 'required|numeric',
            'pod_file' => 'required',
            'letter_file' => 'required',
            'lose_invoice' => 'required',
            'whole_invoice' => 'required',
            'lose_list' => 'required',
            'whole_list' => 'required',
//            'pic_file' => 'required',
        ], [
            'currency_id.required' => '请选择币种',
            'amount.required' => '请填写金额',
            'pod_file.required' => '请上传POD文件',
            'letter_file.required' => '请上传索赔信',
            'lose_invoice.required' => '请上传丢件发票',
            'whole_invoice.required' => '请上传整票发票',
            'lose_list.required' => '请上传丢件箱单',
            'whole_list.required' => '请上传整票箱单',
//            'pic_file.required' => '请上传图片附件'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
